2 using System.Collections.Generic;
5 using Microsoft.Xna.Framework;
6 using Microsoft.Xna.Framework.Graphics;
8 namespace SuperPolarity
12 public enum Polarity : byte { Negative, Positive, Neutral };
15 public Polarity CurrentPolarity;
16 public uint MagneticRadius;
18 protected float FleeVelocity;
19 protected float ActVelocity;
20 protected float ChargeVelocity;
21 protected int RepelRadius;
23 protected bool Magnetizing;
25 public Ship(Game newGame) : base(newGame) {
31 ChargeVelocity = 1.5f;
32 CurrentPolarity = Polarity.Neutral;
36 public virtual void SwitchPolarity()
38 if (CurrentPolarity == Polarity.Positive)
40 CurrentPolarity = Polarity.Negative;
44 CurrentPolarity = Polarity.Positive;
48 public virtual void SetPolarity(Polarity newPolarity)
50 CurrentPolarity = newPolarity;
53 public virtual void Shoot()
57 public override void Update(GameTime gameTime)
59 base.Update(gameTime);
63 public virtual void Magnetize(Ship ship, float distance, float angle)
66 Polarity polarity = ship.CurrentPolarity;
68 if (polarity != CurrentPolarity)
74 Repel(distance, angle);
78 protected void Attract(float angle)
80 Velocity.X = (float) (ChargeVelocity * Math.Cos(angle));
81 Velocity.Y = (float) (ChargeVelocity * Math.Sin(angle));
84 protected void Repel(float distance, float angle)
86 if (distance > RepelRadius) { Magnetizing = false; return; }
87 Velocity.X = -(float)(FleeVelocity * Math.Cos(angle));
88 Velocity.Y = -(float)(FleeVelocity * Math.Sin(angle));